<?php

class Tag_Page{
	static $XSL;
}

Tag_Page::$XSL = <<<EOD
<xsl:template name="search-and-replace">
     <xsl:param name="input"/>
     <xsl:param name="search-string"/>
     <xsl:param name="replace-string"/>
     <xsl:choose>
          <!-- See if the input contains the search string -->
          <xsl:when test="\$search-string and 
                           contains(\$input,\$search-string)">
               <xsl:value-of 
                    select="substring-before(\$input,\$search-string)"/>
               <xsl:value-of select="\$replace-string"/>
               <xsl:call-template name="search-and-replace">
                    <xsl:with-param name="input"
                    select="substring-after(\$input,\$search-string)"/>
                    <xsl:with-param name="search-string" 
                    select="\$search-string"/>
                    <xsl:with-param name="replace-string" 
                        select="\$replace-string"/>
               </xsl:call-template>
          </xsl:when>
          <xsl:otherwise>
               <!-- There are no more occurences of the search string so 
               just return the current input string -->
               <xsl:value-of select="\$input"/>
          </xsl:otherwise>
     </xsl:choose>
</xsl:template>


<xsl:template match="i:pages">
<xsl:variable name="current" select="@current"/>
<xsl:variable name="pagecount" select="@pagecount"/>
<xsl:variable name="baseurl" select="@baseurl"/>
<xsl:variable name="delimiter">
<xsl:choose>
	<xsl:when test="@delimiter">
		<xsl:value-of select="@delimiter"/>
	</xsl:when>
	<xsl:otherwise>
	...
	</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<div class="pages">
	<xsl:for-each select="i:page">
	<xsl:variable name="page-url">
		<xsl:call-template name="search-and-replace">
			<xsl:with-param name="input" select="\$baseurl"/>
			<xsl:with-param name="search-string" select="'[#page]'"/>
			<xsl:with-param name="replace-string" select="@value"/>
		</xsl:call-template>
	</xsl:variable>
		<xsl:choose>
			<xsl:when test="@style='previous'">
				<span class="prev">
				<xsl:if test="@value &gt;= 1">
					<a href="{\$page-url}"><xsl:value-of select="@label"/></a>
				</xsl:if>
				<xsl:if test="@value = 0">
					<xsl:value-of select="@label"/>
				</xsl:if>
				</span>	
			</xsl:when>
			<xsl:when test="@style='next'">
				<span class="next">
				<xsl:if test="@value &lt;= \$pagecount">
					<a href="{\$page-url}"><xsl:value-of select="@label"/></a>
				</xsl:if>
				<xsl:if test="@value &gt; \$pagecount">
					<xsl:value-of select="@label"/>
				</xsl:if>
				</span>
			</xsl:when>
			<xsl:when test="@style='sep'">
				<xsl:value-of select="\$delimiter"/>
			</xsl:when>
			<xsl:otherwise>
				<xsl:if test="\$current!=@value">
				<a href="{\$page-url}"><xsl:value-of select="@label"/></a>
				</xsl:if>
				<xsl:if test="\$current=@value">
				<span class="selected"><xsl:value-of select="@label"/></span>
				</xsl:if>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:for-each>
	
</div>
</xsl:template>
EOD;

